package com.wskj.controller.my;

import com.wskj.common.annotation.RepeatSubmit;
import com.wskj.common.core.controller.BaseController;
import com.wskj.common.core.domain.AjaxResult;
import com.wskj.common.core.page.TableDataInfo;
import com.wskj.common.utils.tool.Query;
import com.wskj.system.service.ISysUserService;
import com.wskj.workbench.bo.app.*;
import com.wskj.workbench.service.ITbUserJoinOrderService;
import com.wskj.workbench.service.ITbUserTiktokService;
import com.wskj.workbench.service.ITbUserWalletDetailService;
import com.wskj.workbench.service.ITbUserWithdrawalService;
import com.wskj.workbench.vo.app.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Api(tags = "【用户端】我的相关接口")
@AllArgsConstructor
@RestController
@RequestMapping("/api/user/center")
public class ApiUserInfoController extends BaseController {

    private final ISysUserService sysUserService;

    private final ITbUserWithdrawalService tbUserWithdrawalService;


    private final ITbUserJoinOrderService tbUserJoinOrderService;

    private final ITbUserWalletDetailService tbUserWalletDetailService;

    private final ITbUserTiktokService tbUserTiktokService;


    @ApiOperation("个人资料-详情")
    @GetMapping(value = "/info")
    public AjaxResult<AppUserInfoVo> info() {
        AppUserInfoVo detail = sysUserService.getDetail();
        return AjaxResult.success(detail);
    }

    @ApiOperation("修改认证消息")
    @PostMapping(value = "/update/auth")
    @RepeatSubmit
    public AjaxResult<AppTbUserJoinOrderVo> updateAuth(@Validated @RequestBody AppTbUserJoinOrderEditBo bo) throws Exception {
        AppTbUserJoinOrderVo result = tbUserJoinOrderService.updateAuth(bo);
        return AjaxResult.success(result);
    }


    @ApiOperation("修改密码")
    @PostMapping(value = "/update/password")
    @RepeatSubmit
    public AjaxResult<Void> updatePassword(@Validated @RequestBody AppUserPasswordEditBo editBo) {
        boolean updateEdit = sysUserService.updatePassword(editBo);
        return toAjax(updateEdit);
    }


    @ApiOperation("我的团队总人数")
    @GetMapping("/team/total")
    public AjaxResult<AppTeamTotalVo> teamTotal() {
        AppTeamTotalVo appTeamTotalVo = sysUserService.teamTotal();
        return AjaxResult.success(appTeamTotalVo);
    }


    @ApiOperation("我的团队")
    @GetMapping("/team/page")
    public TableDataInfo<AppTeamVo> getPageTeam(Query query, @Validated AppSysUserQueryBo bo) {
        return sysUserService.getPageTeam(query, bo);
    }


    @ApiOperation("申请提现")
    @PostMapping(value = "/apply/withdrawal")
    @RepeatSubmit
    public AjaxResult<Void> applyWithdrawal(@Validated @RequestBody AppTbUserWithdrawalAddBo bo) {
        boolean updateEdit = tbUserWithdrawalService.applyWithdrawal(bo);
        return toAjax(updateEdit);
    }


    @ApiOperation("提现记录查看")
    @GetMapping("/withdrawal/record")
    public TableDataInfo<AppTbUserWithdrawalVo> withdrawalRecord(Query query, @Validated AppTbUserWithdrawalQueryBo bo) {
        return tbUserWithdrawalService.withdrawalRecord(query, bo);
    }


    @ApiOperation("我的佣金记录")
    @GetMapping("/wallet/record")
    public TableDataInfo<AppTbUserWalletDetailVo> walletRecord(Query query, @Validated AppTbUserWalletDetailQueryBo bo) {
        return tbUserWalletDetailService.walletRecord(query, bo);
    }


    @ApiOperation("取消审核")
    @PostMapping(value = "/cancleAuth")
    @RepeatSubmit
    public AjaxResult<Void> cancleAuth() {
        boolean result = sysUserService.cancleAuth();
        return toAjax(result);
    }


    @ApiOperation("不再审核")
    @PostMapping(value = "/notAuth")
    @RepeatSubmit
    public AjaxResult<Void> notAuth() {
        boolean result = sysUserService.notAuth();
        return toAjax(result);
    }


    @ApiOperation("修改抖音消息")
    @PostMapping(value = "/update/tiktok")
    @RepeatSubmit
    public AjaxResult<Void> updateTiktok(@Validated @RequestBody AppUpdateTiktokBo bo)  {
        boolean result = tbUserTiktokService.updateTiktok(bo);
        return toAjax(result);
    }


}
